package com.happy_hao.user.controller;

import com.happy_hao.user.common.Result;
import com.happy_hao.user.dto.UpdateUserRequest;
import com.happy_hao.user.service.AdministratorService;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/administrator")
public class AdministratorController {

    @Resource
    private AdministratorService administratorService;

    @GetMapping("/getUserInfo")
    public Result getUserInfo(String username) {
        return administratorService.getUserInfo(username);
    }

    @GetMapping("/getAllUserSimpleInfo")
    public Result getAllUserSimpleInfo() {
        return administratorService.getAllUserSimpleInfo();
    }

    @RequestMapping("/updateUserInfo")
    public Result updateUserInfo(@Valid @RequestBody UpdateUserRequest updateUserRequest) {
        return administratorService.updateUserInfoRequest(updateUserRequest);
    }

    @PostMapping("/addNewGroup")
    public Result addNewGroup(String groupName) {
        return administratorService.addNewGroup(groupName);
    }

    @GetMapping("/getAllGroups")
    public Result getAllGroups() {
        return administratorService.getAllGroups();
    }

    @PostMapping("/bindUserToGroup")
    public Result bindUserToGroup(String groupName, String username) {
        return administratorService.bindUserToGroup(groupName,username);
    }

    @DeleteMapping("/kickUserFromGroup")
    public Result kickUserFromGroup(String groupName, String username) {
        return administratorService.kickUserFromGroup(groupName,username);
    }

    @GetMapping("/getGroupAllUsers")
    public Result getGroupAllUsers(String groupName) {
        return administratorService.getGroupAllUsers(groupName);
    }

    @GetMapping("/getAllPermissions")
    public Result getAllPermissions() {
        return administratorService.getAllPermissions();
    }

    @PostMapping("/bindPermissionToGroup")
    public Result bindPermissionToGroup(String groupName, String permissionName) {
        return administratorService.bindPermissionToGroup(groupName,permissionName);
    }
    @DeleteMapping("/dropPermissionFromGroup")
    public Result dropPermissionFromGroup(String groupName, String permissionName) {
        return administratorService.dropPermissionFromGroup(groupName,permissionName);
    }

}
